package com.ljq.cksp.service.impl;

import com.ljq.cksp.dao.DocumentDao;
import com.ljq.cksp.pojo.Document;
import com.ljq.cksp.service.DocumentService;
import com.ljq.cksp.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author:ljq
 * @Date:2020/4/22
 */
@Service
public class DocumentServiceImpl implements DocumentService {
    @Autowired
    DocumentDao documentDao;

    @Override
    public Page<Document> queryByAccusation(String keyword, int start, int size) {
        start = start<0?0:start;
        return documentDao.findByAccusation(keyword, PageRequest.of(start, size));
    }
    @Override
    public Page<Document> queryByFact(String keyword, int start, int size) {
        start = start<0?0:start;
        return documentDao.findByFact(keyword, PageRequest.of(start, size));
    }
    @Override
    public void saveFromFile(File file) {
        List<Document> documents = JsonUtil.json2Documents(file);
        documentDao.saveAll(documents);
    }
}
